﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Reflection;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace CodeGame
{
    [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
    sealed class LuaHelpAttribute : Attribute
    {

        // See the attribute guidelines at 
        //  http://go.microsoft.com/fwlink/?LinkId=85236
        readonly string positionalString;

        // This is a positional argument
        public LuaHelpAttribute(string positionalString)
        {
            this.positionalString = positionalString;
        }

        public string PositionalString
        {
            get { return positionalString; }
        }
    }

    internal static class Singletons
    {
        public static Dictionary<string, string> LuaHelp = new Dictionary<string, string>();

        public static void BuildLuaHelp(Assembly asm, string space)
        {
            foreach (Type item in asm.GetTypes())
            {
                System.Console.WriteLine(item.FullName);
                if (item.Namespace == space)
                {
                    foreach (MethodInfo item2 in item.GetMethods(BindingFlags.Public | BindingFlags.Static))
                    {
                        string str2 = "";
                        foreach (ParameterInfo item3 in item2.GetParameters())
                        {
                            str2 += item3.ParameterType.Name + " " + item3.Name + ", ";
                        }

                        if (str2.Length > 0)
                        {
                            str2 = str2.Substring(0, str2.Length - 2);
                        }

                        System.Console.WriteLine(item2.Name);
                        object[] items = item2.GetCustomAttributes(false);
                        foreach (object item3 in items)
                        {
                            LuaHelpAttribute attrib = (LuaHelpAttribute)item3;
                            string table = item.Name.Split('_')[1];

                            string str = "(" + str2 + ") " + attrib.PositionalString;
                            if (table == "global")
                            {
                                if (item2.Name.Length > Singletons.MaxLuaHelpLength)
                                {
                                    Singletons.MaxLuaHelpLength = item2.Name.Length;
                                }
                                LuaHelp.Add(item2.Name, str);
                            }
                            else
                            {
                                if ((item.Name.Split('_')[1] + "." + item2.Name).Length > Singletons.MaxLuaHelpLength)
                                {
                                    Singletons.MaxLuaHelpLength = (item.Name.Split('_')[1] + "." + item2.Name).Length;
                                }
                                LuaHelp.Add(item.Name.Split('_')[1] + "." + item2.Name, str);
                            }
                        }
                    }
                }
            }
        }

        public static int MaxLuaHelpLength = 0;

        public static bool IsKeyboardLocked = true;

        public static ContentManager Content;
        public static ScriptingManager Scripting;
        public static NetworkManager Network;
        public static LuaConsole Console;
        public static GlobalStateManager States;
        public static NetworkEntityManager NetworkEntity;
        public static HookManager Hooks;
        public static World CurrentWorld;

        public static GraphicsDevice Device;

        public static Color NormalText = Color.Gray;
        public static Color ErrorText = Color.Red;
        public static Color EntryText = Color.White;
        public static Color OldEntryColor = Color.LightGray;
        public static Color Background = Color.DarkGray;
        public static Color NetworkColor = Color.Purple;
        public static Color WindowColor = new Color(85, 85, 85, 125);
    }
}
